home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992…ugust: Hack to the Future / ADC Developer CD (1992-08) (''Hack To The Future'')_iso / Dev.CD 199208.iso / Technical Documentation / DTS Sample Code / Snippets / OS / VBLThang.p < prev   
Encoding:
Text File  |  1992-07-15  |  983 b   |  43 lines  |  [TEXT/MPS ]

  1. { VBL nonsense for Q&A’s }
  2.  
  3. UNIT PersistentVBL;
  4.  
  5. INTERFACE
  6.  
  7. USES Types,Memory,OSUtils,Retrace;
  8.  
  9. FUNCTION InstallPersistentVBL(VAR theVBLRec: VBLTask): OSErr;
  10.  
  11. IMPLEMENTATION
  12.  
  13. CONST
  14.     JMPInstr = $4EF9;            { This is an absolute JMP }
  15.     JMPSize = 6;                { Size of an absolute JMP }
  16.  
  17. FUNCTION InstallPersistentVBL(VAR theVBLRec: VBLTask): OSErr;
  18.  
  19. TYPE
  20.     ProcPtrPtr = ^ProcPtr;
  21.  
  22. VAR
  23.     theErr: OSErr;
  24.     SysHeapPtr: Ptr;
  25.     tempPtr: Ptr;
  26.  
  27. BEGIN
  28.     SysHeapPtr := NewPtrSys(6);
  29.     theErr := MemError;
  30.     IF theErr <> noErr THEN                            { We are in a WORLD of hurt! }
  31.     BEGIN
  32.         InstallPersistentVBL := theErr;
  33.         EXIT(InstallPersistentVBL);
  34.     END;
  35.     INTEGERPtr(SysHeapPtr)^ := JMPInstr;            { Shove in the JMP }
  36.     tempPtr := Ptr(ORD(SysHeapPtr)+2);                { Expletive deleted }
  37.     ProcPtrPtr(tempPtr)^ := theVBLRec.vblAddr;        { We want to JMP to the original VBL task }
  38.     theVBLREc.vblAddr := ProcPtr(SysHeapPtr);        { Point record at SysHeap }
  39.     InstallPersistentVBL := VInstall(@theVBLRec);    { Install that thang! }
  40. END;
  41.  
  42. END.
  43.